package cn.edu.hatu.bookshop.dao;

import cn.edu.hatu.bookshop.entity.Customer;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface CustomerMapper {
    @Select("select * from customer")
    List<Customer> getAll();

    @Select("select * from customer where customerId = #{customerId}")
    Customer findById(@Param("customerId")int customerId);

    @Select("select * from customer where name = #{name}")
    List<Customer> findByName(@Param("name")String name);

    @Insert("insert into customer(password,name,address,email,telephone)" +
            " values(#{customer.password},#{customer.name},#{customer.address},#{customer.email},#{customer.telephone})")
    void addCustomer(@Param("customer")Customer customer);

    @Delete("delete from customer where customerId=#{customerId}")
    void delById(@Param("customerId")int customerId);

    @Update("update customer set password=#{customer.password},name=#{customer.name},address=#{customer.address}," +
            "email=#{customer.email},telephone=#{customer.telephone} where customerId=#{customer.customerId}")
    void updateCustomer(@Param("customer")Customer customer);

    @Update("update customer set password=#{password} where customerId=#{customerId}")
    void changePassword(@Param("password")String password,@Param("customerId") int customerId);

}
